Add key normalisation functionality #16
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements key normalisation functionality to convert primary and foreign keys in related tables to zero-based sequential indices while preserving relationships.
When constructing microdata, we often work with datasets that have inconsistent key formats - some might use sequential IDs starting from 1, others might use large sparse integers like user IDs 101, 105, 103. This creates unnecessary complexity and memory overhead. By normalising all keys to a common zero-based sequential format, we can assume consistent key patterns across all datasets, simplifying downstream processing and reducing memory usage.
The implementation adds
normalise_table_keys()for multi-table normalisation with relationship preservation andnormalise_single_table_keys()for single table scenarios. Foreign key relationships are automatically detected based on column name matching, though explicit specification is also supported. The functionality handles edge cases like duplicate keys, missing columns, and invalid references with clear error messages.Comprehensive test coverage includes 15 test cases covering normal operations, edge cases, and error handling. All existing tests continue to pass and code is formatted with black and isort.
Fixes #15